home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
- Newsgroups: comp.std.c++
- Subject: friend class declaration and nested classes
- Date: 07 Feb 1996 11:35:04 PST
- Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4fa71q$1rp@fsuj01.rz.uni-jena.de>
- Reply-To: mkt@isun04.inf.uni-jena.de
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 7 Feb 1996 12:47:54 GMT
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMRj/fky4NqrwXLNJAQETYQH/VhV1/6ZEeA/IfUSESHI17d0dt9jLZSUK
- y16jXqc8i2hK92dJDiKxudMhmz4qlBz1bZbGgtiVV2v/0r2eOcH/Wg==
- =jCmg
- Originator: austern@isolde.mti.sgi.com
-
- Consider this:
-
- class X;
-
- class Y {
- class X {};
- friend class ::X; // error!!!
- };
-
- I meet that nice problem when compiling the following code:
-
- class A {
- class B {};
- friend class A::B; // error!!!
- };
-
- Most compilers compile this without a warning. Only the one from
- DEC produced an 'invalid declarator' error.
-
- I watched the ARM and found out:
- Section 11.4: "... All the functions of a class X can be
- made friends of a class Y by a single declaration
- using an 'elaborated-type-specifier' ('9.1):
-
- class Y {
- friend class X;
- // ...
- };"
-
- 'elaborated-type-specifier':
- 'class-key' 'class-name'
- 'class-key' 'identifier'
- enum 'enum-name'
-
- 'class-key':
- class
- struct
- union
-
- 'class-name':
- 'identifier'
-
- In what follows: The examples above are really errors!
- Correcting the second example is easy:
-
- class A {
- class B {};
- friend class B;
- };
-
- But how about the first example?!?!?!?
-
- class X;
-
- class Y {
- class X {};
- friend class X; // That's not what I want!
- class X;
-
- Or:
-
- class X;
-
- class Y {
- friend class X; // Error: violating the rewriting rules!
- class X {};
- };
-
- Bye.
- Tilo Koerbs, mkt@uni-jena.de
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
- in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
-